package com.shoppingCart.controller;

import com.shoppingCart.VO.ResultVO;
import com.shoppingCart.dataobject.Parking;
import com.shoppingCart.enums.ResultEnum;
import com.shoppingCart.exception.ParkingException;
import com.shoppingCart.service.ParkingService;
import com.shoppingCart.utils.ResultVOUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * create By lihao
 */
@Slf4j
@RestController
@RequestMapping("/parking")
public class ParkingController {
    @Autowired
    private ParkingService parkingService;

    @RequestMapping("get_parking_by_place")
    @ResponseBody
    public ResultVO<List<Parking>> parkingList(Map<String,Object> map){
        List<Parking> parkingList= parkingService.findParkingByPlace(map);
        if(parkingList==null){
          log.error("【附近无车】");
          throw new ParkingException(ResultEnum.NO_CAR);
        }
        return ResultVOUtil.success(parkingList);
    }

    @RequestMapping("parking_test")
    @ResponseBody
    public String test(){
        String test="\n" +
                "{\n" +
                "  \"data\": [\n" +
                "    {\n" +
                "      \"id\": 0,\n" +
                "      \"title\": \"去这里\",\n" +
                "      \"iconPath\": \"/images/markers.png\",\n" +
                "      \"latitude\": 29.57506201,\n" +
                "      \"longitude\": 106.60227298,\n" +
                "      \"width\": 45,\n" +
                "      \"height\": 50\n" +
                "    },\n" +
                "    {\n" +
                "      \"id\": 1,\n" +
                "      \"title\": \"去这里\",\n" +
                "      \"iconPath\": \"/images/markers.png\",\n" +
                "      \"latitude\": 29.57648031,\n" +
                "      \"longitude\": 106.60132884,\n" +
                "      \"width\": 45,\n" +
                "      \"height\": 50\n" +
                "    },\n" +
                "    {\n" +
                "      \"id\": 2,\n" +
                "      \"title\": \"去这里\",\n" +
                "      \"iconPath\": \"/images/markers.png\",\n" +
                "      \"latitude\": 29.58704227,\n" +
                "      \"longitude\": 106.77698135,\n" +
                "      \"width\": 45,\n" +
                "      \"height\": 50\n" +
                "    },\n" +
                "    {\n" +
                "      \"id\": 3,\n" +
                "      \"title\": \"去这里\",\n" +
                "      \"iconPath\": \"/images/markers.png\",\n" +
                "      \"latitude\": 28.71259,\n" +
                "      \"longitude\": 115.828344,\n" +
                "      \"width\": 45,\n" +
                "      \"height\": 50\n" +
                "    },\n" +
                "    {\n" +
                "      \"id\": 4,\n" +
                "      \"title\": \"去这里\",\n" +
                "      \"iconPath\": \"/images/markers.png\",\n" +
                "      \"latitude\": 28.717671,\n" +
                "      \"longitude\": 115.825963,\n" +
                "      \"width\": 45,\n" +
                "      \"height\": 50\n" +
                "    },\n" +
                "    {\n" +
                "      \"id\": 5,\n" +
                "      \"title\": \"去这里\",\n" +
                "      \"iconPath\": \"/images/markers.png\",\n" +
                "      \"latitude\": 28.731232,\n" +
                "      \"longitude\": 115.832978,\n" +
                "      \"width\": 45,\n" +
                "      \"height\": 50\n" +
                "    },\n" +
                "    {\n" +
                "      \"id\": 6,\n" +
                "      \"title\": \"去这里\",\n" +
                "      \"iconPath\": \"/images/markers.png\",\n" +
                "      \"latitude\": 28.724559,\n" +
                "      \"longitude\": 115.834195,\n" +
                "      \"width\": 45,\n" +
                "      \"height\": 50\n" +
                "    },\n" +
                "    {\n" +
                "      \"id\": 7,\n" +
                "      \"title\": \"去这里\",\n" +
                "      \"iconPath\": \"/images/markers.png\",\n" +
                "      \"latitude\": 28.682892,\n" +
                "      \"longitude\": 115.858198,\n" +
                "      \"width\": 45,\n" +
                "      \"height\": 50\n" +
                "    }\n" +
                "  ]\n" +
                "}";
        return test;
    }
}
